package com.utils;

import com.pojo.User;

import java.io.Serializable;
public class Result implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;
    private Object data;
    public Result() {}
    public Result(ResultCode rt){
        this.code = rt.code();
        this.msg = rt.message();
    }
    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /*
    * 登录成功
    */
    public static Result LoginSUCCESS(Object user) {
        Result result = new Result();
        result.setResultCode(ResultCode.LOGIN_SUCCESS);
        result.setData(user);
        return result;
    }

    /*用户操作成功*/
    public static Result SUCCESS(Object user,ResultCode resultCode) {
        Result result = new Result();
        result.setResultCode(resultCode);
        result.setData(user);
        return result;
    }

    public void setResultCode(ResultCode code) {
        this.code = code.code();
        this.msg = code.message();
    }

    /**
     * 操作失败，没有返回的数据
     */
    public static Result failure(ResultCode resultCode) {
        Result result = new Result();
        result.setResultCode(resultCode);
        return result;
    }

    /**
     * 操作失败，有返回的数据
     */
    public static Result failure(ResultCode resultCode, Object data) {
        Result result = new Result();
        result.setResultCode(resultCode);
        result.setData(data);
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

